We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How to get the name of the executed controller in $app->after

How to get the name of the executed controller in $app->after

<?php 

class Micro extends \Phalcon\Mvc\Micro
{

  public function init()
  {

    $this->after(function() {

      // print the name of the executed controller here

    });
  }
}

The concept of controllers doesn't exist in Micro apps. However you can access the app object itself this way:

<?php 

class Micro extends \Phalcon\Mvc\Micro
{

  public function init()
  {
    $that = $this;
    $this->after(function() use ($that) {
       echo $that->router->getControllerName();
    });
  }
}